/**  
 * @Project: jeecg
 * @Title: ProcessEndListener.java
 * @Package com.oa.manager.workFlow.listener.execution
 * @date 2013-8-16 下午2:04:12
 * @Copyright: 2013 
 */
package org.jeecg.modules.extbpm.listener.execution;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.extbpm.process.common.WorkFlowGlobals;



/**
 * 	类名：SubProcessStartListener
 * 	功能：子流程启动监听
 * @author zhoujf
 *
 */
public class SubProcessStartListener implements ExecutionListener{

	private static final long serialVersionUID = 1L;

	/**
	 * 这里可以加逻辑，定义给子流程传递变量
	 * @param execution
	 * @throws Exception
	 */
	@Override
	public void notify(DelegateExecution execution) throws Exception {
		
		RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class);
		String mainProcessId = (String)execution.getVariable(WorkFlowGlobals.JG_SUB_MAIN_PROCESS_ID);
		String bizTitle = (String)runtimeService.getVariable(mainProcessId,WorkFlowGlobals.BPM_BIZ_TITLE);
		String businessKey = (String)runtimeService.getVariable(mainProcessId, WorkFlowGlobals.BPM_DATA_ID);
		execution.setVariable(WorkFlowGlobals.BPM_BIZ_TITLE, bizTitle);

		//获取主表表名【online表单需要】
		String tableName = (String)runtimeService.getVariable(mainProcessId,WorkFlowGlobals.BPM_FORM_KEY);
		execution.setVariable(WorkFlowGlobals.BPM_FORM_KEY, tableName);
		//获取主表数据id【online表单需要】
		execution.setVariable(WorkFlowGlobals.BPM_DATA_ID, businessKey);
		//子流程实例set业务号和主流程保持一致
        runtimeService.updateBusinessKey(execution.getProcessInstanceId(), businessKey);
	}

}
